package com.xiaoxu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("A");
    }

    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("B");
    }


    //配置了Swagger的Docket的bean示例
    @Bean
    public Docket docket(Environment environment){


        //开发和测试的情况下enable swagger
        Profiles profiles = Profiles.of("dev", "test");

        boolean flag = environment.acceptsProfiles(profiles);


        environment.getActiveProfiles();
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("SueDawn")
                .select()
                //配置要扫描接口的方式 源码可查
                //扫描特定包 所有 不扫描任何 类注解
                .apis(RequestHandlerSelectors.basePackage("com.xiaoxu.controoler"))
//                .apis(RequestHandlerSelectors.any())
//                .apis(RequestHandlerSelectors.none())
//                .apis(RequestHandlerSelectors.withMethodAnnotation(GetMapping.class))
//                .apis(RequestHandlerSelectors.withClassAnnotation(GetMapping.class))
                //.paths(PathSelectors.ant("/xiaoxu/**"))
                .build()
                .enable(true); //启用swagger
    }
    //配置swagger信息 = apiInfo
    private ApiInfo apiInfo(){
        Contact contact = new Contact("SueDawn", "https://www.bing.com", "1273796085@qq.com");
        return new ApiInfo("Sue Dawn API Documentation",
                "This is for test API Documentation for Sue Dawn",
                "-v1.0",
                "https://www.bing.com",
//                new Contact("", "", ""),
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
